package pro.cherish.knowledgeormmysql.config.mybatis;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/** 
*
* @ClassName   类名：MybatisObjectHandler 
* @Description 功能说明：公用字段自动填充 比如 更新时间 创建时间等
*/
@Component
public class MybatisObjectHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
	    //新增时需要填充字段
		setFieldValByName("createTime", LocalDateTime.now(), metaObject);
		setFieldValByName("modifyTime", LocalDateTime.now(), metaObject);
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		//更新时 需要填充字段
		setFieldValByName("modifyTime", LocalDateTime.now(), metaObject);
	}

}
